<template>
  <div>
    <input type="text" v-show="!flag" ref="input" />
    <button v-show="flag" @click="focusInput">点击搜索</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      flag: true
    }
  },
  methods: {
    focusInput() {
      this.flag = !this.flag
      this.$nextTick(() => {
        this.$refs.input.focus()
      })
    }
  }
}
</script>

<style></style>
